﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="addconsume.aspx.cs" Inherits="App.admin.addconsume" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>添加消费信息</title>
    <link href="../css/default.css" rel="stylesheet" type="text/css" />
    <link rel="stylesheet" type="text/css" href="../css/jquery-ui.css" />
    <%--<link rel="shortcut icon" href="../favicon.ico" />--%>
    <%--<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>--%>
    <script type="text/javascript" src="../javascript/jquery.min.js"></script>
    <script type="text/javascript" src="../javascript/jquery-ui.js"></script>
    <script type="text/javascript" src="../javascript/jquery-ui-slide.min.js"></script>
    <script type="text/javascript" src="../javascript/jquery-ui-timepicker-addon.js"></script>
    <script type="text/javascript">
        $(function () {
            $('#txtConsumeDateTime').datetimepicker();
        });
        function setDefaultDateTime() {
            var ctlStart = this.document.getElementById("txtConsumeDateTime");
            var startDateTime = ctlStart.value;
            var date = new Date();
            var start = date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate() + " " + (date.getHours()) + ":" + date.getMinutes() + ":" + date.getSeconds() + "";
            if (!startDateTime) {
                ctlStart.value = start
            }
        }
        function avgCost() {
            var totalCost = this.document.getElementById("txtCost");
            var showAvgCost = this.document.getElementById("lblAvgCost");
            var re = /^-?[1-9]*(\.\d+)?$|^-?0(\.\d+)?$/;
            if (re.test(totalCost.value)) {
                var total = getItemTotal();
                if (total > 0) {
                    showAvgCost.value = totalCost.value / total;
                } else {
                    showAvgCost.value = "未选择就餐人员！";
                }
            } else {
                totalCost.value = "";
            }
        }
        function getItemTotal() {
            var total = 0;
            var chkControl = document.getElementById("chklConsumePerson");
            var chkItems = chkControl.getElementsByTagName("INPUT");//用innerHTML可以看到checkboxlist的项其实就是很多个input,不能直接chkControl.length,应该用chkItems.length
            for (var i = 0; i < chkItems.length; i++) {
                if (chkItems[i].checked) {
                    total++;
                }
            }
            return total;
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
        <div style="margin: 10px;">
            <table width="100%" border="0">
                <tr>
                    <td align="left" colspan="4">
                        <asp:Label ID="Label1" runat="server" Text="注：带 <font color=red>*</font> 为必填项！"></asp:Label>
                    </td>
                </tr>
                <tr>
                    <td align="right" width="10%">消费日期：<font color="red">*</font></td>
                    <td align="left" width="80%">
                        <input id="txtConsumeDateTime" readonly="readonly" type="text" runat="server" class="newInput" /></td>
                </tr>
                <tr>
                    <td align="right" width="10%">消费人群：<font color="red">*</font></td>
                    <td align="left" width="80%">
                        <asp:CheckBoxList ID="chklConsumePerson" runat="server" RepeatDirection="Horizontal" RepeatColumns="4"></asp:CheckBoxList>
                    </td>
                </tr>
                <tr>
                    <td align="right" width="10%">消费金额：<font color="red">*</font></td>
                    <td align="left" width="80%">
                        <asp:TextBox ID="txtCost" runat="server" class="newInput" onblur="avgCost()"></asp:TextBox>
                        <span runat="server" style="color: red;">人均：<input id="lblAvgCost" type="text" runat="server" readonly="true" />
                        </span>
                        <%--<asp:Label ID="lblAvgCost" ForeColor="Red" runat="server" Text=""></asp:Label>--%>
                    </td>
                </tr>
                <tr>
                    <td align="right" width="10%">票据图片：&nbsp;</td>
                    <td align="left" width="80%">
                        <asp:FileUpload ID="fileUpload" runat="server" />&nbsp;<asp:Button ID="btnUpload" runat="server" Text="上传票据" OnClick="btnUpload_Click" /><asp:HiddenField ID="hfSavePath" runat="server" />
                    </td>
                </tr>
                <tr>
                    <td colspan="2">&nbsp;</td>
                </tr>
                <tr>
                    <td align="right" width="10%"></td>
                    <td align="left" width="35%">
                        <asp:Button ID="btnSubmit" runat="server" Text="提交数据" OnClick="btnSubmit_Click" />
                    </td>
                </tr>
            </table>
        </div>
    </form>
</body>
</html>
